package com.hot100.mid;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 最大正方形
 * @date 2022/9/30 16:26
 */
public class Demo41 {

    public static void main(String[] args) {

    }


    public int maximalSquare(char[][] matrix) {
             int high=matrix.length;
             int wide=matrix[0].length;
             //相当于原数组加了一个边框， 此数组i,j的值相当于 ,原数组 i-1和j-1的所能获取最大正方形的边长
             int[][] square=new int[high+1][wide+1];
             int max=0;
             //从1开始遍历
        for (int i = 1; i <= high; i++) {
            for (int j = 1; j <=wide; j++) {

                //找的是原二维数组是1的值
                if(matrix[i-1][j-1]=='1'){
                    square[i][j] = Math.min(Math.min(square[i-1][j],square[i][j-1]),square[i-1][j-1])+1;
                    max = Math.max(square[i][j],max);
                }
            }

        }
        return max*max;
    }
}
